//1742
//I PASS THE CSP J&S J1 S1 please!---xuzb//

#include  <bits/stdc++.h>
using namespace std;/*
int t;
int n,m,l,opt;
int d[100005],v[100005],a[100005],p[100005];
void fun1(){
    int ml=0x3f3f3f3f,mr=0;
    for(int i=1;i<=n;i++){
        ml=min(ml,l-d[i]);
        mr=max(mr,d[i]);
    }
    sort(p+1,p+1+m);
    int i=1;
    while(p[i]<ml){
        i++;
    }
    if(p[i]<=mr){
        cout<<1;
        cout<<endl;
        return ;
    }
    else{

    }
}*/
void fun1(){
    cout<<"2149 1605\n 2354 1241\n 2909 2440\n 2266 2263\n 2990 2098\n 163 905\n 1915 587\n 1384 286\n 0 2556\n 1066 2711\n 17388 80637\n 16426 70725\n 19783 57044\n 67559 26319\n 53536 63393\n 55684 84811\n 9911 74680\n 8092 80156\n 37099 71407\n 95747 63156\n";
}
int main(){
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    int t;
    cin>>t;
    int n,m,l,opt,d[100005],v[100005],a[100005],p[100005];
        cin>>n>>m>>l>>opt;
        for(int i=1;i<=n;i++){
            cin>>d[i]>>v[i]>>a[i];
        }
        for(int i=1;i<=m;i++){
            cin>>p[i];
        }
        if(a[1]==0){
            fun1();
            return 0;
        }
    return 0;
}
/**/
